package com.parachutes.aspbillapi.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

public class OrderNumberGenerator {
    private static final AtomicInteger counter = new AtomicInteger(1);
    private static final int MAX_COUNT = 999;

    public static synchronized String generateOrderNumber() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String timestamp = dateFormat.format(new Date());

        // 获取递增的流水号，并确保它是三位数，不足前补零
        int count = counter.getAndIncrement();
        if (count > MAX_COUNT) {
            counter.set(1);
            count = 1;
        }

        return timestamp + String.format("%03d", count);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            System.out.println(generateOrderNumber());
        }
    }
}
